{% include "../public/min-header.html" %}
<style>
ul.group-list {
    width: 96%;
    min-width: 1000px;
    margin: auto 5px;
    list-style: disc outside none;
}
ul.group-list li {
    white-space: nowrap;
    float: left;
    width: 150px;
    height: 25px;
    padding: 3px 5px;
	list-style-type: none;
    list-style-position: outside;
    border: 0px;
    margin: 0px;
}
th.title {
    background: #F3F3F3;
    border-bottom: 1px solid #D7D7D7;
    font-weight: bold;
    white-space: nowrap;
}
</style>
<div class="wrapper">
	{% include "../public/breadcrumb.html" %}
	<section class="content">
	<div class="row">
		<div class="col-sm-12">		        	
			<form id="submitRoleForm" method="post">
			<input type="hidden" name="role_id" value="{{detail.role_id}}" />
			<table class="table table-bordered table-striped">
				<tr>
					<th>角色名称:</th>
					<td><div class="col-xs-6"><input type="text" class="form-control" name="data[role_name]" id="role_name" value="{{detail.role_name}}"></div></td>
					<th >角色描述:</th>
					<td><textarea rows="2" name="data[role_desc]">{{detail.role_desc}}</textarea></td>
					<th>分配权限:</th>
					<th class=""><input class="allChoose" name="" onclick="choosebox(this)" type="checkbox">全部选中</th>
					<td class=""><a href="javascript:void(0)" class="btn btn-info" id="submitRole" data-post-url="{{helper.pathFor('adadri')}}" data-jump-url="{{helper.pathFor('adadrl')}}" >保存</a></td>
				</tr>
			</table>
			<table class="table table-bordered table-striped dataTable">
				{% for v in menu_tree %}
					{% for vv in v.menu%}
						{% if vv %}
						<tr>
							<td class="title left" style="padding-right:50px;">
								{{v.title}} &gt; {{vv.title}}
								<noempty name="vv.menu">
									<label class="right"><input type="checkbox" value="1" cka="mod-{{vv.mod_id}}">全部子模块</label>
								</noempty>
							</td>
						</tr>
						<tr>
							<td>
								<ul class="group-list">
								{% for vvv in vv.menu %}
									{% if vvv %}
									<li><label><input type="checkbox" name="menu[]" {%if vvv.enable == 1 %}checked{% endif %} value="{{vvv.mod_id}}" ck="mod-{{vv.mod_id}}">{{vvv.title}}</label></li>
									{% endif%}
								{% endfor %}
								<div class="clear-both"></div>
								</ul>
							</td>
						</tr>
						{% endif %}
					{% endfor %}
				{% endfor %}
			</table>
			<div class="page-bar">
				<table>
					<tr>
                        <input type="hidden" name="act" value="{{act}}">
						<td><label><input class="allChoose" name="" onclick="choosebox(this)" type="checkbox">全部选中</label></td>
						<td class="page-list"></td>
					</tr>
				</table>
			</div>
			</form>
		</div>
	</div></section>
</div>
<script type="text/javascript">
$(document).ready(function(){
	$(":checkbox[cka]").click(function(){
		var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");;
		if($(this).is(':checked')){
			$cks.each(function(){$(this).prop("checked",true);});
		}else{
			$cks.each(function(){$(this).removeAttr('checked');});
		}
	});
});

function choosebox(o){
	var vt = $(o).is(':checked');
	if(vt){
		$('input[type=checkbox]').prop('checked',vt);
	}else{
		$('input[type=checkbox]').removeAttr('checked');
	}
}

function roleSubmit(){
	if($('#role_name').val() == '' ){
		layer.alert('角色名称不能为空', {icon: 2});  //alert('少年，角色名称不能为空');
		return false;
	}
	$('#roleform').submit();
}

$("#submitRole").click(function(){
    var postData = $("#submitRoleForm").serializeArray();
    var post_url = $(this).attr('data-post-url');
    var jump_url = $(this).attr('data-jump-url');
    $.ajax({
        type: 'POST',
        url: post_url,
        data: postData,
        dataType: 'JSON',
        success: function(result) {
            if(result.status == 1) {
                if(jump_url){
                    setTimeout(()=>{
                        location.href = jump_url;
                    },2000);
                }
                return layer.msg(result.message);
            }else if(result.status == 0) {
                return layer.msg(result.message);
            }
        }
    });
});
</script>

{% include "../public/main-footer.html" %}